<?php
/**
 * Created by PhpStorm.
 * User: Lenovo
 * Date: 2019/4/27
 * Time: 19:30
 */

namespace app\api\model;

use think\Db;

class Myself extends BaseModel
{
    protected $table='jc_user';
    //头像、姓名、邀请码
    public function myself($uid)
    {
        return  $rs=$this->where('uid',$uid)->find();
    }
    //个人信息修改
    public function myxinxi($uid)
    {
        $name=input('name');//姓名
        $sex=input('sex');//性别
        $qq=input('qq');//qq
        $weixin=input('weixin');//微信号
        $alipay=input('alipay');//支付宝
        $card=input('');//省份证号
        $rs=$this->where('uid',$uid)->update(['u_name'=>$name,'u_sex'=>$sex,'u_qq'=>$qq,'wx_no'=>$weixin,'alipay'=>$alipay]);
        return $rs;
    }
    //订单取消列表
    public function indent_cancel($uid)
    {
        $page=input('page');
        $rs=IndentQxModel::where('uid',$uid)->field('tid,t_number')->page($page,'10')->select();
        if(empty($rs))
        {
            $rs=array();
        }
        return $rs;
    }
    //订单取消列表详情
    public function indent_cancel_x($tid)
    {
        $rs=IndentQxModel::where('tid',$tid)->find();
        $info = IndentModel::where("t_number",$rs['t_number'])->find();
        $rs['z_shoutime'] = $info['z_createtime'];
        $rs['z_successtime'] = $rs['z_createtime'];
        return $rs;
    }
    //订单成功列表
    public function indent_success($uid)
    {
        $page=input('page');
        $rs=IndentModel::where('uid',$uid)->where('sid','in','3,6')->field('tid,t_number')->page($page,'10')->select();
        if(empty($rs))
        {
            $rs=array();
        }
        return $rs;
    }
    //订单成功列表详细页面
    public function indent_success_x($tid)
    {
        $rs=IndentModel::where('tid',$tid)->field('t_number,t_money,zid,z_createtime,z_datime,z_shoutime,z_successtime,sid')->find();

        $rs['z_shoutime'] = $rs['z_createtime'];
        $rs['z_successtime'] = $rs['z_datime'];
        if($rs['zid']=='1')
        {
            $rs['zid']='微信';
        }
        if($rs['zid']=='')
        {
            $rs['zid']='支付宝';
        }
        if($rs['zid']=='')
        {
            $rs['zid']='银行卡';
        }
        return $rs;
    }
    //代收款列表
    public function indent_dai($uid)
    {
        $page=input('page');
        $rs=IndentModel::where('uid',$uid)->where('sid','in','2,4')->field('tid,t_number')->page($page,'10')->select();
        if(empty($rs))
        {
            $rs=array();
        }
        return $rs;
    }
    //代收款列表详细页面
    public function indent_dai_x($tid)
    {
        $rs=IndentModel::where('tid',$tid)->field('t_number,t_money,zid,z_createtime,z_shoutime,z_successtime,sid')->find();
        $rs['z_shoutime'] = $rs['z_createtime'];
        $rs['z_successtime'] = '';
        if($rs['zid']=='1')
        {
            $rs['zid']='微信';
        }
        if($rs['zid']=='2')
        {
            $rs['zid']='支付宝';
        }
        if($rs['zid']=='3')
        {
            $rs['zid']='银行卡';
        }
        return $rs;
    }

    //保证金支出明细
    public function baomoney($uid)
    {
        $page=input('page');
        $rs=Baomoney::where('uid',$uid)->page($page,'10')->select();
        foreach ($rs as $k=>$v)
        {
            $rs[$k]['money']=IndentModel::where('tid',$v['tid'])->value('t_money');
            $zid=IndentModel::where('tid',$v['tid'])->value('zid');
            if($zid=='1')
            {
                $rs[$k]['zid']='微信';
            }
            if($zid=='2')
            {
                $rs[$k]['zid']='支付宝';
            }
            if($zid=='3')
            {
                $rs[$k]['zid']='银行卡';
            }
            //$a=$money['t_money'];
            //=$money[];
        }
        if(empty($rs))
        {
            $rs=array();
        }
        return $rs;
    }
    //提现记录(未测)
    public function tixian_record($uid)
    {
        $rs=Withdrawal::where('uid',$uid)->where('w_state',3)->field('wid,w_createtime,w_money')->select();
        if(empty($rs))
        {
            $rs=array();
        }
        return $rs;
    }
    //体现方式
    public function tixian_way($uid,$zid)
    {
        if($zid!=3)
        {
            $rs=QrcodeModel::where('uid',$uid)->where('zid',$zid)->where('q_state',1)->select();
            foreach ($rs as $k=>$v)
            {
                if(empty($v['qid']))
                {
                    return $qid=$v['qid'];
                }
            }
        }
        else
        {
            $rs=BankModel::where('uid',$uid);
        }
    }
    //发起提现创建订单（未测）
    public function tixian_add($uid,$qid=0,$bid=0)
    {
        Db::startTrans();
        $number=date('YmdHis').$uid.rand(0,100);
        $money=input('money');
        $time=date('Y-m-d H:i:s');
        $descs=input('descs');
        //$qid=input('qid');//支付主键连接方式微信,支付宝
        //$bid=input('bid');//支付主键连接方式(银行卡)
        $rs=Withdrawal::insert(['w_number'=>$number,'uid'=>$uid,'w_money'=>$money,'w_createtime'=>$time,'w_descs'=>$descs,'qid'=>$qid,'bid'=>$bid]);
        if($rs)
        {
            Db::commit();
        }
        else
        {
            Db::rollback();
        }
        return $rs;
    }


    //充值信用额度
    public function chongmoney($uid)
    {
        $number='C'.date('YmdHis').$uid.rand(0,100);//echo $uid;die;
        $money=input('money');
        $zid=input('zid');
        $time=date('Y-m-d H:i:s');
        $descs=input('descs');
        $rs=Chongzhi::insert(['c_number'=>$number,'uid'=>$uid,'zid'=>$zid,'c_createtime'=>$time,'c_descs'=>$descs,'c_state'=>1,'c_money'=>$money]);
        return $rs;
    }

    //充值记录
    public function chong_record($uid)
    {
        $page=input('page');
        $rs=Chongzhi::where('uid',$uid)->where('c_state',3)->page($page,'10')->select();
        foreach ($rs as $k=>$v)
        {
            if($v['zid']=='1')
            {
                $rs[$k]['zid']='微信';
            }
            if($v['zid']=='2')
            {
                $rs[$k]['zid']='支付宝';
            }
            if($v['zid']=='3')
            {
                $rs[$k]['zid']='银行卡';
            }
        }
        if(empty($rs))
        {
            $rs=array();
        }
        return $rs;
    }

    //余额明细
    public function yue_details($uid)
    {
        //佣金列表
        $rs=Log::where('uid',$uid)->field('lid,zid,l_yongjin,w_createtime')->select();
        foreach ($rs as $k=>$v)
        {
            if($v['zid']=='1')
            {
                $v['zid']='微信';
            }
            if($v['zid']=='2')
            {
                $v['zid']='支付宝';
            }
            if($v['zid']=='3')
            {
                $v['zid']='银行卡';
            }
        }
        //待收款金额
        $rs2=IndentModel::where('uid',$uid)->where('sid',3)->field('tid,t_usermoney,z_quetime,zid')->select();
        if(empty($rs2))
        {

        }
        foreach ($rs2 as $k=>$v)
        {
            $rs2[$k]['lid']=0;
            if($v['zid']=='1')
            {
                $rs2[$k]['zid']='微信';
            }
            if($v['zid']=='2')
            {
                $rs2[$k]['zid']='支付宝';
            }
            if($v['zid']=='3')
            {
                $rs2[$k]['zid']='银行卡';
            }
            $rs2[$k]['l_yongjin']=$v['t_usermoney'];
            $rs2[$k]['w_createtime']=$v['z_quetime'];
        }
        //dump($this->objectToarray($rs2));
        $rs=array_merge($rs2,$rs);
        if(empty($rs))
        {
            $rs=array();
        }
        return $rs;
    }

    //保证金明细
    public function bao_details($uid)
    {
        $rs=BalancelogModel::where('uid',$uid)->where('type',1)->where('from_type',2)->select();
        if(empty($rs))
        {
            $rs=array();
        }
        else
        {
            foreach ($rs as $k=>$v)
            {
                if($v['zid']=='1')
                {
                    $rs[$k]['zid']='微信';
                }
                if($v['zid']=='2')
                {
                    $rs[$k]['zid']='支付宝';
                }
                if($v['zid']=='3')
                {
                    $rs[$k]['zid']='银行卡';
                }
            }
        }
        return $rs;
    }
}